/**
   UserMessageServiceImpl
 * Time:2018年6月6日
 */
package com.ssm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssm.dao.UsermessageMapper;
import com.ssm.entity.Page;
import com.ssm.entity.Usermessage;
import com.ssm.entity.UsermessageExample;
import com.ssm.entity.UsermessageExample.Criteria;
import com.ssm.entity.UsermessageExample.Criterion;
import com.ssm.service.UserMessageService;

/**
 * @author 15199
 *
 */
@Service("userMessageService")
public class UserMessageServiceImpl implements UserMessageService {

	/* (non-Javadoc)
	 * @see com.ssm.service.UserMessageService#getAll(com.ssm.entity.Page, com.ssm.entity.Usermessage)
	 */
	@Resource
	private UsermessageMapper usermessageMapper;



	@Override
	public List<Usermessage> getAll(Page page, Usermessage usermessage) {
		// TODO Auto-generated method stub
		UsermessageExample usermessageExample=new UsermessageExample();


		usermessageExample.setPage(page);


		Criteria criteria=usermessageExample.createCriteria();


		if(usermessage.getUserid()!=null){


			criteria.andUseridEqualTo(usermessage.getUserid());


		}
		if(usermessage.getUserstate()!=null){


			criteria.andUseridEqualTo(usermessage.getUserstate());


		}



		return usermessageMapper.selectByExample(usermessageExample);
	}



	/* (non-Javadoc)
	 * @see com.ssm.service.UserMessageService#getCount()
	 */
	@Override
	public int getCount() {

		UsermessageExample usermessageExample=new UsermessageExample();


		// TODO Auto-generated method stub
		return usermessageMapper.countByExample(usermessageExample);
	}



	/* (non-Javadoc)
	 * @see com.ssm.service.UserMessageService#updateStats(com.ssm.entity.Usermessage)
	 */
	@Override
	public void updateStats(Usermessage usermessage) {
		// TODO Auto-generated method stub

		UsermessageExample usermessageExample=new UsermessageExample();
		Usermessage usermessage1=usermessageMapper.selectByPrimaryKey(usermessage.getUserid());
		if(usermessage1.getUserstate()==1){
			usermessage1.setUserstate(0);
			usermessageMapper.updateByPrimaryKeySelective(usermessage1);	
		}else{
			usermessage1.setUserstate(1);
			usermessageMapper.updateByPrimaryKeySelective(usermessage1);
		}

	}



	/* (non-Javadoc)
	 * @see com.ssm.service.UserMessageService#checkLogin(com.ssm.entity.Usermessage)
	 */
	@Override
	public List<Usermessage> checkLogin(Usermessage usermessage) {
		// TODO Auto-generated method stub
		UsermessageExample usermessageExample=new UsermessageExample();

		if(usermessage.getUserid()!=null){

			usermessageExample.or().andUseridEqualTo(usermessage.getUserid());

		}

		if(usermessage.getUserpassword()!=null){

			usermessageExample.or().andUserpasswordEqualTo(usermessage.getUserpassword());

		}




		return usermessageMapper.selectByExample(usermessageExample);
	}






}
